package com.enqualcomm.kids.mvp.pedometer;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.enqualcomm.kids.view.BasePager;

import java.util.List;

public class PedometerAdapter extends PagerAdapter {
	private List<BasePager> pages;
	public PedometerAdapter(List<BasePager> pages){
		this.pages = pages;
	}
	
	@Override
	public int getCount() {
		return pages.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0==arg1;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(pages.get(position).getRootView());
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View rootView = pages.get(position).getRootView();
		container.addView(rootView);
		return rootView;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return pages.get(position).getPageTitle();
	}
	
	private int getRealPosition(int position){
		return position%pages.size();
	}
	
}